<?php
require_once '../../../config/koneksi.php';
require_once '../../../config/class_paging_param.php';
?>
<link href="../../../asset/css/admin_style.css" type="text/css" rel="stylesheet">
<link href="../../../asset/js/jquery-1.8.2.min.js" type="text/css" rel="stylesheet">
<link href="../../../asset/css/paging.css" type="text/css" rel="stylesheet">
<script src="../../../asset/js/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
function buka_pesan(target){
		$('#'+target).show(500);
	}
	var count_obat=1;
	function setParent(id_obat, nama,harga,div_pesan) {
        var tampil_tombol_aksi = '<a href="javascript:void(null)" title="Hapus" onclick="hapusObat(this)"><img src="asset/images/button-delete.gif" alt="Hapus" border=0 /></a>';
		var counter= window.opener.document.getElementById("count_obat").value;
  		var tr = window.opener.document.createElement('tr');
  		var td_nama_obat = window.opener.document.createElement('td');
		var td_jumlah = window.opener.document.createElement('td');
		var td_jumlah_diminta = window.opener.document.createElement('td');
		var td_harga = window.opener.document.createElement('td');
		var td_harga_diminta = window.opener.document.createElement('td');
  		var td_aksi = window.opener.document.createElement('td');  		
  		var tbodi = window.opener.document.getElementById("tbody_list_obat");
  		
  		td_aksi.className = 'links';
  		td_aksi.width = 15;
  		td_nama_obat.innerHTML = nama+'<input type="hidden" name="id_obat[]" id="id_obat_'+ counter +'" value="'+ id_obat +'">';
		td_jumlah.innerHTML = '<input type="text" size="5" name="jumlah_obat[]" id="jumlah_obat_'+ counter +'" value="1">';
		td_jumlah_diminta.innerHTML = '<input type="text" size="5" name="jumlah_obat_minta[]" id="jumlah_obat_minta_'+ counter +'" value="1">';
		td_harga.innerHTML = harga;
		td_harga_diminta.innerHTML = '<input type="text" size="5" name="harga_obat[]" id="harga_obat_'+ counter +'" value="'+harga+'">'+'<input type="hidden" size="5" name="harga_obat_awal[]" id="harga_obat_awal_'+ counter +'" value="'+harga+'">';
		
  		td_aksi.innerHTML = tampil_tombol_aksi;
  		
  		tr.appendChild(td_nama_obat);
		tr.appendChild(td_jumlah);
		tr.appendChild(td_jumlah_diminta);
		tr.appendChild(td_harga);
		tr.appendChild(td_harga_diminta);

  		tr.appendChild(td_aksi);
  		tbodi.appendChild(tr);
		//alert(counter);
		counter++;
		window.opener.document.getElementById('count_obat').value =counter;
		window.opener.kalkulasi_obat();
		buka_pesan(div_pesan);
		//window.opener.document.getElementById('total_angka_kredit').innerHTML = parseFloat(window.opener.document.getElementById('total_angka_kredit').innerHTML)+xnilai;
  }
</script>
<?php
	if(!empty($_GET['nama'])){
		$param_nama=$_GET['nama'];
	}else{
		$param_nama=$_POST['nama'];
	}
?>
<form method=post action="">
	<table style="margin-left: 5px;" width="780" >
		<tr>
			<td width="65">Pencarian  : </td>
			<td width="200"><input type="text" name="nama" value="<?php echo $param_nama; ?>" class="input_field" /></td>
			<td><input name="submit" type="submit" class="button" value="Cari" /></td>
		</tr>
	</table>
</form>
<table class="tabel2">
	<tr>
		<th>NO</th>
		<th>Nama Obat </th>
		<th>Harga</th>
		<th>Aksi</th>
		<th></th>
	</tr>
<?php
$p= new paging ;
		$batas= 10;
		$id_ppk=$_GET['id_ppk'];
		//cek halaman dan posisi halaman
		$posisi = $p ->cariposisi($batas) ;
		$sql="SELECT a.kode_obat as id,a.nama_obat ,b.tarif  FROM master_obat a LEFT JOIN tarif_obat b ON a.kode_obat=b.id_obat where nama_obat like '%$param_nama%' and id_ppk='$id_ppk' order by nama_obat asc limit $posisi,$batas";
		//echo $sql;
		$qry=mysql_query($sql);
		$no=$posisi + 1;
//$sql="select * from master_diagnosis";
//$qry=mysql_query($sql);
//$no=1;
while($hasil=mysql_fetch_array($qry)){
?>
	<tr>
		<td align="center" width="30"><?php echo $no;?></td>
		<td ><?php echo $hasil['nama_obat'];?></td>
		<td align="left" width="60"><?php echo $hasil['tarif'];?></td>
		<td align="center" width="60">
			<a href="javascript:setParent('<?php echo $hasil['id']?>','<?php echo $hasil['nama_obat']?>','<?php echo $hasil['tarif']?>','target_pesan_<?php echo $no;?>')" onclick=""><img src="../../../asset/images/button-check.gif"></a>	</td>
		<td><div id="target_pesan_<?php echo $no;?>" style="display:none;">Data Sudah Dipilih</div></td>
	</tr>
<?php
$no++;
}
?>
</table>
<?php
	$sql2="SELECT a.kode_obat id,a.nama_obat ,b.tarif  FROM master_obat a LEFT JOIN tarif_obat b ON a.kode_obat=b.id_obat where nama_obat like '%$param_nama%' and id_ppk='$id_ppk'" ;
	$query2=mysql_query($sql2);
	$jumlah_data=mysql_num_rows($query2);
	//dapatkan jumlah halaman
	$jumlah_halaman= $p->jumlahhalaman($jumlah_data,$batas);
	//cetak link
	$linkhalaman=$p->navhalaman($_GET['halaman'],$jumlah_halaman,$_SERVER['PHP_SELF']."?","nama=$param_nama");
	print($linkhalaman);
?>